﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RuleOfReady.Core.Utility
{

    /// <summary>
    /// Extension methods for enums
    /// </summary>
    /// <remarks>
    /// Multiple posters at stackoverflow.com helped with these methods
    /// </remarks>
    public static class EnumExtensions
    {
        /// <summary>
        /// Generic version of GetValues method (why isn't this in the .Net Framework already?)
        /// </summary>
        /// <typeparam name="TEnum">Type of an enum</typeparam>
        /// <param name="someEnum"></param>
        /// <returns></returns>
        /// <remarks>
        /// There is no proper type check for an Enum. This is as close as possible in C# 
        /// </remarks>
        public static IEnumerable<TEnum> GetValues<TEnum>(this TEnum someEnum) 
            where TEnum : struct, IConvertible, IComparable, IFormattable 
        {
            if (!typeof(TEnum).IsEnum)
                throw new ArgumentException(string.Format("{0} must be an enumerated type", 
                                            typeof(TEnum).FullName));

            return Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
        }
    }
}
